import request from '@/utils/request'
import qs from 'qs'

// 获取fbox token
export const getFboxToken = () => {
  const data = {
    scope: 'fbox',
    client_id: '68db2e8bda8d47b5b5db7eaf71c7dcdd',
    client_secret: '76dc724c95004acab25482d344dab407',
    grant_type: 'client_credentials'
  }
  
  return request({
    url: '/fbox/token',
    method: 'post',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: qs.stringify(data)
  })
}

// 获取传感器数据
export const getSensorData = (boxNo: string, sensorIds: string[]) => {
  return request({
    url: '/fbox/sensor/data',
    method: 'post',
    params: { boxNo },
    data: { ids: sensorIds }
  })
}

// 获取萤石云token
export const getYsToken = (accountId: string) => {
  return request({
    url: '/ys/token',
    method: 'post',
    data: { accountId }
  })
}

// 获取摄像头抓拍
export const getCapture = (params: {
  accessToken: string,
  deviceSerial: string,
  channelNo?: string,
  quality?: number
}) => {
  return request({
    url: '/ys/capture',
    method: 'post',
    params
  })
}

// 获取传感器历史数据
export const getSensorHistory = (deviceId: string, hours: number = 24) => {
  return request({
    url: '/fbox/history',
    method: 'get',
    params: {
      deviceId,
      hours
    }
  })
} 